package cn.tedu.kcircle.common.handler;


import cn.tedu.kcircle.common.exception.BusinessException;
import cn.tedu.kcircle.common.restful.JsonResult;
import cn.tedu.kcircle.common.restful.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 全局异常处理器
 */
@Slf4j
public class GlobalControllerExceptionHandler {
    /**
     * 处理业务异常
     */
    @ExceptionHandler
    public JsonResult<Void> handleBusinessDemoException(BusinessException e) {
        log.error("业务异常",e);
        return JsonResult.failed(e);
    }

    /**
     * 处理系统（其它）异常
     */
    @ExceptionHandler
    public JsonResult<Void> handleThrowable(Throwable e) {
        log.error("未知错误",e);
        return JsonResult.failed(ResponseCode.INTERNAL_SERVER_ERROR, e);
    }
}